﻿using System;
using System.Xml;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Net;
using System.IO;

namespace GDI_Testes
{
    [TestClass]
    public class ServiceTest
    {
        [TestMethod]
        public void GravaAssinaturaDigitalizada_TestMethod()
        {
            HttpWebRequest req = null;
            HttpWebResponse res = null;
            try
            {
                const string url = "http://192.168.160.145/Utilizador.svc/GravaAssinaturaDigitalizada";
                //const string url = "http://localhost:31521/Utilizador.svc/GravaAssinaturaDigitalizada";
                req = (HttpWebRequest)WebRequest.Create(url);
                req.Method = "POST";
                req.ContentType = "application/json; charset=UTF-8";
                req.Timeout = 30000;
                req.Headers.Add("SOAPAction", url);

                StreamReader reader = new StreamReader(@"C:\Users\brazeta\Documents\visual studio 2010\Projects\GDI_WebServices\GDI_Testes\JSON_GravaAssinatura.txt");
                string json = reader.ReadToEnd();

                req.ContentLength = json.Length;

                var sw = new StreamWriter(req.GetRequestStream());
                sw.Write(json);
                sw.Close();

                res = (HttpWebResponse)req.GetResponse();
                Stream responseStream = res.GetResponseStream();
                var streamReader = new StreamReader(responseStream);

                string s = streamReader.ReadToEnd();
                Assert.IsTrue(!string.IsNullOrEmpty(s));
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.ToString());
            }
        }

        [TestMethod]
        public void DevolveDocumentosUser_TestMethod()
        {
            HttpWebRequest req = null;
            HttpWebResponse res = null;
            try
            {
                const string url = "http://192.168.160.145/Utilizador.svc/DevolveDocumentosUser";
                //const string url = "http://localhost:31521/Utilizador.svc/DevolveDocumentosUser";
                req = (HttpWebRequest)WebRequest.Create(url);
                req.Method = "POST";
                req.ContentType = "application/json; charset=UTF-8";
                req.Timeout = 30000;
                req.Headers.Add("SOAPAction", url);

                StreamReader reader = new StreamReader(@"C:\Users\brazeta\Documents\visual studio 2010\Projects\GDI_WebServices\GDI_Testes\JSON_DevolveDocumentosUser.txt");
                string json = reader.ReadToEnd();

                req.ContentLength = json.Length;

                var sw = new StreamWriter(req.GetRequestStream());
                sw.Write(json);
                sw.Close();

                res = (HttpWebResponse)req.GetResponse();
                Stream responseStream = res.GetResponseStream();
                var streamReader = new StreamReader(responseStream);

                string s = streamReader.ReadToEnd();
                Assert.IsTrue(!string.IsNullOrEmpty(s));
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.ToString());
            }
        }

        [TestMethod]
        public void ConsultaSaldo_TestMethod()
        {
            HttpWebRequest req = null;
            HttpWebResponse res = null;
            try
            {
                const string url = "http://192.168.160.145/Utilizador.svc/ConsultaSaldo";
                //const string url = "http://localhost:31521/Utilizador.svc/ConsultaSaldo";
                req = (HttpWebRequest)WebRequest.Create(url);
                req.Method = "POST";
                req.ContentType = "application/json; charset=UTF-8";
                req.Timeout = 30000;
                req.Headers.Add("SOAPAction", url);

                string json = "2588";

                req.ContentLength = json.Length;

                var sw = new StreamWriter(req.GetRequestStream());
                sw.Write(json);
                sw.Close();

                res = (HttpWebResponse)req.GetResponse();
                Stream responseStream = res.GetResponseStream();
                var streamReader = new StreamReader(responseStream);

                string s = streamReader.ReadToEnd();
                Assert.IsTrue(!string.IsNullOrEmpty(s));
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.ToString());
            }
        }
    }
}
